Connect to active Geometric model in DGN file
Every DGN has at least one Model. When you execute code withing a DGN, it considers current DGN to get models for further activities. At least one civil object should be present in the model to get the active geometric model, otherwise the function GetActiveGeometricModel() returns null. The below code snippet shows how to get Geometric model from current dgn.
internal bool ConnectToActiveGeometricModel()
{
//Get Connection to Active DGN
Bentley.DgnPlatformNET.DgnModel activeModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();
//Create ConsensusConnection object
Bentley.CifNET.SDK.ConsensusConnection con = new Bentley.CifNET.SDK.ConsensusConnection(activeModel);
//Get active Geometric model
Bentley.CifNET.GeometryModel.SDK.GeometricModel geomModel = con.GetActiveGeometricModel();
if (geomModel == null)
return false;
return true;
}